package com.aizuda.boot.modules.business.performance.mapper;


import com.aizuda.boot.modules.business.contract.entity.ContractTypeEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ContractTypeMapper extends BaseMapper<ContractTypeEntity> {
    // 查询所有一级类别及其子类别
    @Select("SELECT * FROM contract_type WHERE parent_id IS NULL ORDER BY type_order")
    @Results({
        @Result(property = "id", column = "id"),
        @Result(property = "children", column = "id",
                javaType = List.class,
                many = @Many(select = "com.fim.keyaccount.fimai.aidb.type.mapper.ContractTypeMapper.findByParentId"))
    })
    List<ContractTypeEntity> findAllParentTypesWithChildren();

    // 根据父ID查询子类别
    @Select("SELECT * FROM contract_type WHERE parent_id = #{parentId} ORDER BY type_order")
    List<ContractTypeEntity> findByParentId(@Param("parentId") Integer parentId);

}